import json
import sys
import os
import shutil
import types
from PIL import Image
names = [{"size":16,"name":"Icon-16.png"},
		{"size":20,"name":"Icon-20.png"},
		{"size":28,"name":"Icon-28.png"},
		{"size":29,"name":"Icon-29.png"},
		{"size":32,"name":"Icon-32.png"},
		{"size":36,"name":"Icon-36.png"},
		{"size":40,"name":"Icon-40.png"},
		{"size":48,"name":"Icon-48.png"},
		{"size":50,"name":"Icon-50.png"},
		{"size":57,"name":"Icon-57.png"},
		{"size":58,"name":"Icon-58.png"},
		{"size":60,"name":"Icon-60.png"},
		{"size":64,"name":"Icon-64.png"},
		{"size":72,"name":"Icon-72.png"},
		{"size":76,"name":"Icon-76.png"},
		{"size":80,"name":"Icon-80.png"},
		{"size":87,"name":"Icon-87.png"},
		{"size":90,"name":"Icon-90.png"},
		{"size":96,"name":"Icon-96.png"},
		{"size":100,"name":"Icon-100.png"},
		{"size":108,"name":"Icon-108.png"},
		{"size":114,"name":"Icon-114.png"},
		{"size":120,"name":"Icon-120.png"},
		{"size":128,"name":"Icon-128.png"},
		{"size":144,"name":"Icon-144.png"},
		{"size":152,"name":"Icon-152.png"},
		{"size":155,"name":"Icon-155.png"},
		{"size":167,"name":"Icon-167.png"},
		{"size":180,"name":"Icon-180.png"},
		{"size":192,"name":"Icon-192.png"},
		{"size":256,"name":"Icon-256.png"},
		{"size":512,"name":"Icon-512.png"},
		{"size":1024,"name":"Icon-1024.png"},
		{"size":256,"name":"ic_launcher.png"},
		]
def changeSize(infile,outfile,size):
	# infile = '.\\icon.png'
	# outfile = '.\\icon2.png'
	im = Image.open(infile)
	(x,y) = im.size #read image size
	x_s = size #define standard width
	y_s = y * x_s / x #calc height based on standard width
	out = im.resize((x_s,y_s),Image.ANTIALIAS) #resize image with high-quality
	out.save(outfile)
	print 'original size: ',x,y
	print 'adjust size: ',x_s,y_s
	print "save file======",outfile
if __name__=="__main__":
	print "=========================Publish Icon begin============================"
	dirname = os.path.join(sys.path[0],"icon")
	if not os.path.isdir(dirname):
		os.makedirs(dirname,0777)
	for data in names:
		# data = names[key]
		changeSize(os.path.join(sys.path[0],"icon.png"),os.path.join(dirname,data["name"]),data["size"])
	print "=========================Publish Icon end============================"
